package com.example.aicloud.config;

import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import org.springframework.boot.web.client.RestClientCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.nio.charset.StandardCharsets;

@Configuration
public class AIConfig {

    @Bean
    public RestClientCustomizer restClientCustomizer() {
        return restClientBuilder -> restClientBuilder.requestInterceptor((request, body, execution) -> {
            // 使用 jackson 解析请求体，去掉 temperature 参数
            JSONObject entries = JSONUtil.parseObj(new String(body));
            entries.remove("temperature");
            return execution.execute(request, entries.toString().getBytes(StandardCharsets.UTF_8));
        }).build();
    }
}